package app.r_teenus.backend.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Filter;
import org.hibernate.annotations.FilterDef;
import org.hibernate.annotations.FilterDefs;
import org.hibernate.annotations.ParamDef;


@Entity
@Table(name = "ENTERPRISE")
@FilterDefs({ @FilterDef(name = "SUBJECT_TYPE", parameters = @ParamDef(name = "SUBJECT_TYPE", type = "integer")), 
	@FilterDef(name = "CONTACT_TYPE", parameters = @ParamDef(name = "CONTACT_TYPE", type = "integer")),
	@FilterDef(name = "SUBJECTATTRIBUTE_TYPE", parameters = @ParamDef(name = "SUBJECTATTRIBUTE_TYPE", type = "integer")),
	@FilterDef(name = "ENT_CUSTOMER_TYPE", parameters = @ParamDef(name = "ENT_CUSTOMER_TYPE", type = "integer")) })
public class Enterprise implements Serializable {

	private static final long serialVersionUID = 4319694251468158190L;

	private Integer id;
	private String name;
	private String fullName;
	private Employee createdBy;
	private Date created;
	private Employee updatedBy;
	private Date updated;
	private List<Address> addresses = new ArrayList<Address>();
	private List<Contact> contacts = new ArrayList<Contact>();
	private List<Employee> employee = null;
	private List<Customer> customer = null;
	private boolean canRemove = false;
	/**
	 * Gets id (primary key).
	 */
	@Id
	@Column(name = "ENTERPRISE")
	@SequenceGenerator(name = "enterprise_id", sequenceName = "enterprise_id", allocationSize = 1)
	@GeneratedValue(generator = "enterprise_id")
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	/**
	 * Gets list of <code>Contact</code>es.
	 */
	@OneToMany(mappedBy = "subject", cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.REMOVE })
	@Filter(name = "CONTACT_TYPE", condition = "SUBJECT_TYPE_FK= :CONTACT_TYPE")
	public List<Contact> getContacts() {
		return contacts;
	}

	public void setContacts(List<Contact> contacts) {
		this.contacts = contacts;
	}

	/**
	 * Gets list of <code>Address</code>es.
	 */
	@OneToMany(mappedBy = "subject", cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.REMOVE })
	@Filter(name = "SUBJECT_TYPE", condition = "SUBJECT_TYPE_FK= :SUBJECT_TYPE")
	public List<Address> getAddresses() {
		return addresses;
	}

	/**
	 * Sets list of <code>Address</code>es.
	 */
	public void setAddresses(List<Address> addresses) {
		this.addresses = addresses;
	}

	/**
	 * Gets full_name.
	 */
	@Column(name = "FULL_NAME")
	public String getFullName() {
		return fullName;
	}

	public void setFullName(String fullName) {
		this.fullName = fullName;
	}

	@OneToOne(cascade = { CascadeType.REFRESH })
	@JoinColumn(name = "UPDATED_BY", nullable = true)
	public Employee getUpdatedBy() {
		return updatedBy;
	}

	public void setUpdatedBy(Employee updatedBy) {
		this.updatedBy = updatedBy;
	}

	@OneToOne(cascade = CascadeType.REFRESH)
	@JoinColumn(name = "CREATED_BY")
	public Employee getCreatedBy() {
		return createdBy;
	}

	public void setCreatedBy(Employee createdBy) {
		this.createdBy = createdBy;
	}

	public Date getCreated() {
		return created;
	}

	public void setCreated(Date created) {
		this.created = created;
	}

	public Date getUpdated() {
		return updated;
	}

	public void setUpdated(Date updated) {
		this.updated = updated;
	}
	
	@OneToMany(cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.REMOVE })
	@JoinColumn(name = "PERSON_FK")
	public List<Employee> getEmployee() {
		return employee;
	}

	public void setEmployee(List<Employee> employee) {
		this.employee = employee;
	}
	
	@OneToMany(cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.REMOVE }, fetch = FetchType.EAGER)
	@JoinColumn(name = "SUBJECT_FK")
	@Filter(name = "ENT_CUSTOMER_TYPE", condition = "SUBJECT_TYPE_FK= :ENT_CUSTOMER_TYPE")
	public List<Customer> getCustomer() {
		return customer;
	}

	public void setCustomer(List<Customer> customer) {
		this.customer = customer;
	}
	
	@Transient
	public boolean isCanRemove() {
		return canRemove;
	}

	public void setCanRemove(boolean canRemove) {
		this.canRemove = canRemove;
	}
	
	
}
